package cn.com.dcsgo.config;

import cn.hutool.core.lang.Snowflake;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 订单编号配置类
 *
 * @author Dcsgo
 * @since 2025/11/18 10:37
 */
@Data
@RefreshScope
@Configuration
@NoArgsConstructor
@AllArgsConstructor
public class OrderIdConfig {
    /**
     * 工作机器ID
     */
    @Value("${order.id.workerId}")
    private Long workerId;

    /**
     * 数据中心ID
     */
    @Value("${order.id.dataCenterId}")
    private Long dataCenterId;

    @Bean
    public Snowflake snowflake() {
        return new Snowflake(workerId, dataCenterId);
    }
}
